#include <iostream>
#include <utility>
#define PLB pair<long long, bool>
#define x first
#define y second  //1: red, 0: blue
using namespace std;
PLB a[200020];

long long dfs(int n, int i, int lastr, int lastb){
    //cout << i << endl;
    if (i == n){
        return 0;
    }
    long long c = 0;
    if (lastb != -1 && a[lastb].x == a[i].x){
       c = a[lastb].x;
    }
    //cout << "1:" << c << endl;
    long long t = dfs(n, i + 1, lastr, i);
    a[i].y = 1;
    if (lastr != -1 && a[lastr].x == a[i].x){
       c = a[lastr].x;
    }
    //cout << "2:" << c << endl;
    t = max(t, dfs(n, i + 1, i, lastb));
    return c + t;
}
int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    cin >> t;
    int n;
    for (int i = 0; i < t; i ++){
        cin >> n;
        for (int j = 0; j < n; j ++){
            cin >> a[j].x;
        }
        cout << dfs(n, 0, -1, -1) <<  endl;
    }
    return 0;
}
